;(function(undefined) {
    "use strict"
    var _global;

    function result(args,fn){
        var argsArr = Array.prototype.slice.call(args);
        if(argsArr.length > 0){
            return argsArr.reduce(fn);
        } else {
            return 0;
        }
    }
    var  rightsList = {
        columnsInit:function(){
            return  [{
            	checkbox: true
            },{
                field: 'roleName',
                width: '100px',
                title: '角色名称'
            },{
                field: 'roleCode',
                title: '角色编码'
            }]
        },
        usercolumnsInit:function(){
            return  [{
            	checkbox: true
            },{
                field: 'userName',
                width: '100px',
                title: '角色名称'
            },{
                field: 'userCode',
                title: '角色编码'
            }]
        },
        gridInit:function(columns){
            return $("#allTable").bootstrapTable({
                url:'',
                columns: columns,
                striped: 'true',
                clickToSelect: true,
                classes: 'table table-hover qxttable',
                height: 305
            })

        },
        usergridInit:function(columns){
            return $("#selectTable").bootstrapTable({
                url:'',
                columns: columns,
                striped: 'true',
                clickToSelect: true,
                classes: 'table table-hover qxttable',
                height: 305
            })

        },
        dataInit:function(){
            return  [{
                roleName: '111',
                roleCode: '555464545',
            },{
                roleName: '111',
                roleCode: '555464545',
            },{
                roleName: '111',
                roleCode: '555464545',
            },{
                roleName: '111',
                roleCode: '555464545',
            },{
                roleName: '111',
                roleCode: '555464545',
            },{
                roleName: '111',
                roleCode: '555464545',
            },{
                roleName: '111',
                roleCode: '555464545',
            },{
                roleName: '111',
                roleCode: '555464545',
            },{
                roleName: '111',
                roleCode: '555464545',
            },{
                roleName: '111',
                roleCode: '555464545',
            },{
                roleName: '111',
                roleCode: '555464545',
            },{
                roleName: '111',
                roleCode: '555464545',
            }]
        },
        userdataInit:function(){
            return  [{
                userName: '李四',
                userCode: '555464545',
            },{
                userName: '王五',
                userCode: '555464545',
            },{
                userName: '李四',
                userCode: '555464545',
            },{
                userName: '王五',
                userCode: '555464545',
            },{
                userName: '李四',
                userCode: '555464545',
            },{
                userName: '王五',
                userCode: '555464545',
            },{
                userName: '李四',
                userCode: '555464545',
            },{
                userName: '王五',
                userCode: '555464545',
            },{
                userName: '李四',
                userCode: '555464545',
            },{
                userName: '王五',
                userCode: '555464545',
            },{
                userName: '李四',
                userCode: '555464545',
            },{
                userName: '王五',
                userCode: '555464545',
            }]
        }
    }

    // 将插件对象暴露给全局对象
    _global = (function(){ return this || (0, eval)('this'); }());
    if (typeof module !== "undefined" && module.exports) {
        module.exports = rightsList;
    } else if (typeof define === "function" && define.amd) {
        define(function(){return rightsList;});
    } else {
        !('plugin' in _global) && (_global.rightsList = rightsList);
    }
}());
$(function () {
    //渲染表格
    var columns = rightsList.columnsInit();
    var table = rightsList.gridInit(columns);
    var datas = rightsList.dataInit();
    var usercolumns = rightsList.usercolumnsInit();
    var usertable = rightsList.usergridInit(usercolumns);
    var userdatas = rightsList.userdataInit();
    $("#allTable").bootstrapTable("append",datas);
    $("#selectTable").bootstrapTable("append",userdatas);
    //搜索
    $('#serachBtn').on('click',function(){
    	$("#allTable").bootstrapTable("refresh");
    })
    $('#serachBtn1').on('click',function(){
    	$("#selectTable").bootstrapTable("refresh");
    })
    //重置
    $('#searchReset').on('click',function(){
    	$('#searchForm input').val('');
    	$("#allTable").bootstrapTable("refresh");
    })
    $('#searchReset1').on('click',function(){
    	$('#searchForm1 input').val('');
    	$("#selectTable").bootstrapTable("refresh");
    })
    //左边选中，箭头变蓝
    function changeStatus(obj,index){
    	var allLen=$(obj).length;
	    if(allLen > 0){
	    	$('.click-arrow-btn').eq(index).addClass('click-arrow-on');
	    }else{
	    	$('.click-arrow-btn').eq(index).removeClass('click-arrow-on');
	    }
    }
    $("#allTable input").on('change',function(){
    	changeStatus("#allTable input[name='btSelectItem']:checked",0);
    })
    $("#allTable, #allTable input:checkbox").on('click',function(){
    	changeStatus("#allTable input[name='btSelectItem']:checked",0);
    });
    $("#selectTable input").on('change',function(){
    	changeStatus("#selectTable input[name='btSelectItem']:checked",1);
    })
    $("#selectTable, #selectTable input:checkbox").on('click',function(){
    	changeStatus("#selectTable input[name='btSelectItem']:checked",1);
    });
})